<template>
  <div>
    <div>
      <el-button type="primary" @click="toFormHandler">新增</el-button>
      <el-table :data="dataset" style="width: 100%">
        <el-table-column prop="name" label="应用名称" width="180">
        </el-table-column>
        <el-table-column prop="introduce" label="介绍" width="180">
        </el-table-column>
        <el-table-column prop="photo" label="照片链接"> </el-table-column>
        <el-table-column width="100" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="editHandler(scope.row)"
              >修改</el-button
            >
            <el-button type="text" @click="deleteHandler(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { del, get } from "@/utils/request";
export default {
  data() {
    return {
      dataset: [],
      visible: false
    };
  },
  methods: {
    loadDataset() {
      let url = "http://120.77.41.127:8888/dataset/query";
      get(url).then(resp => {
        this.dataset = resp.data;
      });
    },
    toFormHandler() {
    this.$router.push({ path: "/ldd/Dataset_Form" });
  },
  editHandler(row) {
    this.$router.push({
      path: "/ldd/Dataset_Form",
      query: row
    });
  },
  deleteHandler(row) {
    this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }).then(() => {
      let url = "http://120.77.41.127:8888/dataset/deleteById";
      del(url, { id: row.id }).then(resp => {
        // 1. 提示
        this.$message({ type: "success", message: resp.message });
        // 2. 刷新
        this.loadDataset();
      });
    });
  },
  },
  
  created() {
    this.loadDataset();
  }
};
</script>

<style lang="sass" scoped>

</style>
